package com.cy.pj.common.web.advice;

import com.cy.pj.common.web.pojo.JsonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * 此注解描述的类为全局异常类
 */
@RestControllerAdvice
public class GlobarExceptionHandler {
    private static final Logger log=
            LoggerFactory.getLogger(GlobarExceptionHandler.class);//门面模式
    public JsonResult dohandleNumberFormatException(NumberFormatException e){
        e.printStackTrace();
        log.error("exception{}", "你传入的参数值不匹配");
        return new JsonResult(0,"你传入的参数值类型不匹配");
    }

    /**
     * @ExceptionHandler 注解描述的方法为异常处理方法,
     * 注解中定义的异常类型为方法可以处理的异常类型.
     */
    public JsonResult doHandleRuntimeException(RuntimeException e){
        e.printStackTrace();
        log.error("exception msg is {}", e.getMessage());//打印到控制台，写在日志上记录
        return new JsonResult(e);
    }
}
